package org.jeecg.modules.operations.assistant.xcbd.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.concurrent.atomic.AtomicInteger;

public class DailySequence {

    private static final AtomicInteger SEQUENCE = new AtomicInteger(0);
    private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMdd");
    private static String currentDate;

    public static synchronized String getDailySequence() {
        String today = DATE_FORMAT.format(new Date());
        if (!today.equals(currentDate)) {
            SEQUENCE.set(0); // 重置为0
            currentDate = today;
        }
        int sequence = SEQUENCE.incrementAndGet(); // 递增
        return String.format("GZXC%s%03d", currentDate, sequence);
    }

    public static void main(String[] args) {

        for (int i = 0; i < 10; i++) {
            System.out.println(getDailySequence());
        }
        currentDate="20241231";
        for (int i = 0; i < 10; i++) {
            System.out.println(getDailySequence());
        }
    }
}
